package{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.utils.ByteArray;
	import morn.core.handlers.Handler;
	/**
	 * 注册所有的游戏资源
	 * @author ...
	 */
	public class RegAssets{
		[Embed(source="../bin/assets/comp.swf", mimeType="application/octet-stream")]
		private var compClass:Class;
		
		
		/**加载资源的Loader*/
		private var loader:Loader;
		/**所有需要嵌入的资源*/
		private var assets:Array;
		/**当前加载的进度*/
		private var loaderIndex:int;
		/**加载完成资源以后的回调函数*/
		private var callback:Handler;
		public function RegAssets(callback:Handler){
			this.allClass=[this.compClass];
			
			this.callback=callback;
			this.loaderIndex=-1;
			this.loader=new Loader();
			this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.embedAssets);
			this.embedAssets();
		}
		private function embedAssets(evt:Event=null):void{
			this.loaderIndex++;
			if(this.loaderIndex>=this.assets.length){
				this.callback.execute();
				return;
			}
			this.loader.loadBytes(ByteArray(new assets[this.loaderIndex]()),new LoaderContext(false, ApplicationDomain.currentDomain));
		}
	}
}